package com.victor.pomelo.dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.victor.pomelo.model.Group;
import com.victor.pomelo.model.User;

public interface GroupMapper {
	@Select("SELECT * FROM user WHERE id = #{Id}")
	User getUser(@Param("Id") String userId);

	@Select("select * from tb_group where parentid = #{parentid}")
	List<Group> findChild(@Param("parentid") Long parentid);

	@Select("select a.groupid, a.parentid, a.name, a.description, a.state , a.cretime, a.updtime, a.updreason, if(count(b.groupid) > 0, false, true) as isleaf "
			+ " from tb_group a left join tb_group b on a.groupid = b.parentid "
			+ " where a.parentid = #{parentid}"
			+ " group by a.groupid, a.parentid, a.name, a.description, a.state, a.cretime, a.updtime, a.updreason")
	List<Group> findChildren(@Param("parentid") Long parentid);

	@Select("SELECT COUNT(*) as count FROM accounts)")
	Integer accountCount();
}